<template>
  <div id="app-page" v-loading="loading" :style="{opacity: loading?0:1}">
    <div class="header" >
      <Header/>
    </div>
    <div style="display: flex">
      <div class="aside" :style="{width:asideWidth+'%'}">
        <Aside/>
        <Fold v-if="homeStore.state.expand===true" class="aside-icon"
              :style="{marginLeft: 'calc('+asideWidth+'% - 25px)',opacity:asideIconOpacity}" @click="foldAside"/>
        <Expand v-if="homeStore.state.expand===false" class="aside-icon"
                :style="{marginLeft: 'calc('+asideWidth/2+'% - 10px)',opacity:asideIconOpacity}" @click="expandAside"/>
      </div>
      <div class="container" :style="{width:(100 - asideWidth)+'%'}">
        <router-view/>
      </div>
    </div>

  </div>

</template>

<script setup>
import {ref, watch} from 'vue';
import {useRoute} from "vue-router";
import Header from "@/Music/components/Header";
import Aside from "@/Music/components/Aside";
import {Expand, Fold} from "@element-plus/icons-vue";
import {homeStore} from "@/store/home";

let loading = ref(true);

let route = useRoute();
// 侧边栏宽度
let asideWidth = ref(15);
// 左侧栏图标展开
let expand = ref(true);
// 左侧栏图标不透明度
let asideIconOpacity = ref(1);

function foldAside() {
  asideIconOpacity.value = 0;
  homeStore.state.expand = false;
  asideWidth.value = 4;
  setTimeout(() => {
    asideIconOpacity.value = 1;
  }, 500)
}

function expandAside() {
  asideIconOpacity.value = 0;
  homeStore.state.expand = true;
  asideWidth.value = 15;
  setTimeout(() => {
    asideIconOpacity.value = 1;
  }, 500)
}

watch(route, () => {
  setTimeout(() => {
    loading.value = false
  }, 500)
}, {immediate: true})

</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
}

#app-page {
  width: 100vw;
  height: 100vh;
  min-width: 1080px;
//min-height: 720px;
  box-sizing: border-box;
}

#app-page .header {
  height: 6vh;
  width: 100%;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  box-shadow: 0 0 6px 0px #c6c6c6;
  background-color: var(--main-color);
  color: #fff;
  padding: 0 15px;
}

#app-page .aside {
  width: 15%;
  height: 94vh;
  box-sizing: border-box;
  box-shadow: 0 5px 12px 0px #c6c6c6;
  transition: width 0.5s ease;
}

#app-page .aside .aside-icon {
  width: 20px;
  height: 20px;
  display: flex;
  margin-left: auto;
  color: #8f8f8f;
  position: absolute;
  bottom: 5px;
  transition: opacity 1s ease;
}

#app-page .aside .aside-icon:hover {
  cursor: pointer;
  transform: scale(1.1);
}

#app-page .container {
  width: 85%;
  height: 94vh;
  padding: 15px;
  box-sizing: border-box;
  background-color: rgb(238, 240, 244);
  transition: width 0.5s ease;
}


</style>
